home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
051-075
/
disk_054
/
miditools
/
getmidi.c
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
4KB
|
158 lines
/****************************************************************************
Author: Fred Cassirer
Date: January 24, 1987
This program is placed in the public domain, and from what I understand
that means anyone can do whatever they want with it. That's fine
because they are fairly trivial anyway ... If you can get someone to pay
you for them, you must be doing something right.
****************************************************************************/
/* compiler directives to fetch the necessary header files */
#include <libraries/dos.h>
#include <exec/types.h>
#include <exec/exec.h>
#include <devices/serial.h>
#include <stdio.h>
#include <ctype.h>
#include <functions.h>
#include "midi.h"
#undef NULL
#define NULL ((void *)0)
extern long SetSignal();
breakcheck()
{
if (SetSignal(0L,0L) & SIGBREAKF_CTRL_C )
return ( 1 );
else
return( 0 );
}
breakreset()
{
SetSignal(0L, SIGBREAKF_CTRL_C);
}
/* this routine causes manx to use this Chk_Abort() rather than it's own */
/* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
/* is zero). Since we want to check for our own ^C's */
Chk_Abort()
{
return(0);
}
/* declarations for the serial stuff */
extern struct MsgPort *CreatePort();
struct IOExtSer *Read_Request;
static unsigned char rs_in[2];
struct IOExtSer *Write_Request;
static unsigned char rs_out[2];
void initmidi()
{
Read_Request = (struct IOExtSer *)AllocMem((long)sizeof(*Read_Request),MEMF_PUBLIC|MEMF_CLEAR);
Read_Request->io_SerFlags = SERF_SHARED | SERF_RAD_BOOGIE;
Read_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0);
if(OpenDevice(SERIALNAME,NULL,Read_Request,NULL))
{
puts("Cant open Read device\n");
DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort);
FreeMem(Read_Request,(long)sizeof(*Read_Request));
exit(TRUE);
}
Read_Request->IOSer.io_Length = 1;
Read_Request->IOSer.io_Data = (APTR) &rs_in[0];
Read_Request->io_Baud = 31250;
Read_Request->io_ReadLen = 8;
Read_Request->io_WriteLen = 8;
Read_Request->io_CtlChar = 1L;
Read_Request->IOSer.io_Command = SDCMD_SETPARAMS;
DoIO(Read_Request);
Read_Request->IOSer.io_Command = CMD_READ;
Write_Request = (struct IOExtSer *)AllocMem((long)sizeof(*Write_Request),MEMF_PUBLIC|MEMF_CLEAR);
Write_Request->io_SerFlags = SERF_SHARED | SERF_RAD_BOOGIE;
Write_Request->io_StopBits = 1;
Write_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",0);
if(OpenDevice(SERIALNAME,NULL,Write_Request,NULL))
{
puts("Can't open Write device\n");
DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort);
FreeMem(Write_Request,(long)sizeof(*Write_Request));
DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort);
FreeMem(Read_Request,(long)sizeof(*Read_Request));
exit(TRUE);
}
Write_Request->IOSer.io_Command = CMD_WRITE;
Write_Request->IOSer.io_Length = 1;
Write_Request->IOSer.io_Data = (APTR) &rs_out[0];
Write_Request->io_SerFlags = SERF_SHARED | SERF_XDISABLED;
BeginIO(Read_Request);
breakreset();
}
void cleanup()
{
CloseDevice(Read_Request);
DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort);
FreeMem(Read_Request,(long)sizeof(*Read_Request));
CloseDevice(Write_Request);
DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort);
FreeMem(Write_Request,(long)sizeof(*Write_Request));
}
/************************************************************/
/* send midi data to the serial port */
/************************************************************/
int putmidi(ch)
int ch;
{
rs_out[0] = ch;
DoIO(Write_Request);
return(ch);
}
/******************************************************/
/* This routine will return an unsigned */
/* byte of midi data. */
/******************************************************/
int getmidi()
{
int c;
Wait( (1L << Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit)
| (SIGBREAKF_CTRL_C) );
if(CheckIO(Read_Request))
{
WaitIO(Read_Request);
c=rs_in[0];
BeginIO(Read_Request);
}
else
c = NON_MIDI_EVENT;
return(c);
}